package com.example.test.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;

/**
 * @ClassName: 林文峰
 * @Author Administrator
 * @Date 2020/6/16 0016
 */
@Controller
@RequestMapping("/wx")
public class WxTestController {

	@RequestMapping("/weChat")
	@ResponseBody
	public String test(String signature,String timestamp,String nonce,String echostr){
		//1. 将token、timestamp、nonce三个参数进行字典序排序
		String[] arr = {timestamp,nonce,"admin"};
		Arrays.sort(arr);
		//2. 将三个参数字符串拼接成一个字符串进行sha1加密
		StringBuilder sb = new StringBuilder();
		for (String temp : arr) {
			sb.append(temp);
		}
		//3. 开发者获得加密后的字符串可与signature对比，标识该请求来源于微信。这里简单输出一下
		System.out.println(signature+" : "+timestamp+" : "+nonce+" : "+echostr);
		//接入失败
		return echostr;
	}
}
